﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MShop.Core.Domain
{

    [MetadataType(typeof(CartItem_Validation))]
    public partial class CartItem
    {

        public CartItem()
        {
            this.Created = DateTime.Now;
        }

        public bool IsEmpty
        {
            get
            {
                return string.IsNullOrEmpty(SkuId);
            }
        }


        public decimal TotalPrice
        {
            get
            {
                return this.Price * this.Quanitiy;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            if(obj is CartItem)
            {
                CartItem A =(CartItem)obj ;
                if (IsEmpty)
                {
                    return this.Id == A.Id;
                }
                else
                {
                    if (this.Id == A.Id)
                    {
                        SkuEntity s1 = new SkuEntity(this.SkuId);
                        SkuEntity s2 = new SkuEntity(A.SkuId);
                        return s1 == s2;
                    }
                }
            
            }
            return false;
        }        

        public override int GetHashCode()
        {
            return this.Id.GetHashCode() ^ this.SkuId.GetHashCode();
        }
    }

    internal partial class CartItem_Validation
    { 
         
    }
}